import 'package:flutter/foundation.dart';
import 'package:syria_sports/core/app_export.dart';
import 'package:flutter/material.dart';
import '../../../data/controllers/gyms_controller.dart';
import '../../../dialogs/delete_player_confirmation.dart';
import '../../gyms/gym_info_page/gym_info_screen.dart';
import '../../gyms/gyms_page/models/gym.dart';


class GymItemView extends StatelessWidget {
  final Gym gym;
  const GymItemView({super.key, required this.gym});

  @override
  Widget build(BuildContext context) {

    return InkWell(
      onTap: (){
         Navigator.push(context, MaterialPageRoute(builder: (context1) => GymInfoScreen.builder(context, gym,false),));
      },
      child: Padding(
        padding: const EdgeInsets.all(8.0),
        child: Card(
          color: Colors.white30,
          margin:const EdgeInsets.symmetric(vertical: 4,horizontal: 8),
          child: Container(
            clipBehavior: Clip.antiAlias,
            width: 250,
            decoration: BoxDecoration(
              gradient: LinearGradient(
                begin: Alignment.topCenter,
                end: Alignment.bottomCenter,
                colors: [
                  Colors.black.withOpacity(.5),
                  Colors.transparent,
                  Colors.transparent,
                  Colors.black.withOpacity(.5),
                ],
              ),
              borderRadius: BorderRadius.circular(4),
              image: DecorationImage(
                  fit:(gym.image==null)? null:BoxFit.cover,
                  isAntiAlias: true,
                  opacity: .7,
                  image:(gym.image!=null)?Image.network(gym.image!).image:Image.asset(ImageConstant.imgLogo).image
              ),
            ),
            child: Container(
              padding:const EdgeInsets.all(4),
              decoration: BoxDecoration(
                gradient: LinearGradient(
                  begin: Alignment.topCenter,
                  end: Alignment.bottomCenter,
                  colors: [
                    Colors.black.withOpacity(1),
                    Colors.transparent,
                    Colors.transparent,
                    Colors.black.withOpacity(1),
                  ],
                ),
                borderRadius: BorderRadius.circular(4),
              ),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Row(
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: [
                      Expanded(
                        child: Column(
                          mainAxisAlignment: MainAxisAlignment.start,
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Text(gym.name, style: theme.textTheme.titleMedium!.copyWith(color: Colors.white),),
                            SizedBox(
                              child: Text(
                                gym.workingHours,
                                maxLines: 5,
                                style: theme.textTheme.titleMedium!.copyWith(fontSize: 14),),
                            ),
                          ],
                        ),
                      ),

                    ],
                  ),
                  Align(
                    alignment: Alignment.centerRight,
                    child: Text(gym.description, style: theme.textTheme.titleSmall,),
                  ),
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
  void showDeleteConfirmation(BuildContext context, Gym myGym) {
    showDialog(
      context: context,
      builder: (BuildContext context) {
        return DeleteConfirmationDialog(
          playerName: myGym.name,
          titleUser: 'النادي',
          onConfirm: () {
            GymsController.deleteById(gym.gymId??'-1');
            if (kDebugMode) {
              print('تم حذف النادي ${gym.name}!');
            }
          },
        );
      },
    );
  }
}
